/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.interpreter.backends.rdf;

/**
 *
 * @author Laurent WOUTERS
 */
public class DefaultEntityCreator implements EntityCreator {
    private static final java.util.Random rand = new java.util.Random();
    
    private xowl.interpreter.IRIProvider provider;
    
    public DefaultEntityCreator(xowl.interpreter.IRIProvider provider) {
        this.provider = provider;
    }

    @Override public xowl.lang.owl2.IRI createIRI(xowl.lang.owl2.Ontology ontology) {
        String iri = ontology.getHasIRI().getHasValue() + "#gen" + generateID();
        return provider.getIRI(iri);
    }
    
    private static String generateID() {
        StringBuilder builder = new StringBuilder();
        String value = Integer.toHexString(rand.nextInt()).toUpperCase();
        for (int i=0; i!=8-value.length(); i++)
            builder.append('0');
        builder.append(value);
        return builder.toString();
    }
}
